home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: gets() question
- Date: 9 Jan 1996 19:20:06 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4cuf56$frd@news.iag.net>
- References: <4cosgf$rir@newsbf02.news.aol.com> <4cqkt8$1quo@news.gate.net>
- NNTP-Posting-Host: pm1-orl4.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4cqkt8$1quo@news.gate.net>, bhutto@gate.net says...
- <snip>
- >> char s[3][10];
- >>
- >> printf ("Enter s[0]: ");
- >> gets (s[0]);
- > ^^^^
- >
- >Your compiler didn't generate an error? *s* is not an array of pointers to
- >arrays of chars as in argv[]. Now I remember why I always like being
- explicit.
- >Try this:
- >
- > fgets(&s[0][0],9,stdin);
- >
- >You can use a 2 dimensional char array, except that you have to be complete
- >in your form and s[0] is not. Because fgets() (or gets() for that matter) is
- >looking for an address, you need to oblige, hence the prefix of *&*.
-
- Unless someone's changed the rules very recently, his expression was quite
- legal, though the use of gets is generally undesirable.
-
- Check out K&R II A8.6.2 P217:
-
- ".......Also,
- static int x3d[3][5][7];
- declares a static three-dimensional array of integers, with rank 3x5x7. In
- complete detail, x3d is an array of three items; each item is an array of five
- items; each of the latter arrays is an array of seven integers. Any of the
- expressions x3d, x3d[i], x3d[i][j], x3d[i][j][k] may reasonably appear in an
- expression. Teh first three have type "array", the last has type int. More
- specifically, x3d[i][j] is an array of 7 integers, and x3d[i] is an array of
- 5 arrays of 7 integers."
-
- So s[0] would be type "array of 10 chars". By 7.1 this would decay to a
- pointer to the first char in the array.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-